import { daysOfWeek, months } from "./data";

export const toDate = (time) => {
  let date = new Date(time);

  let dayOfMonth = date.getDate();
  let dayOfWeek = daysOfWeek[date.getDay()];

  let monthIndex = date.getMonth();
  let month = months[monthIndex];

  var formattedDate = dayOfMonth + " " + month + ", " + dayOfWeek;

  return formattedDate;
};

export const toUniqueDateArray = (data) => {
  let uniqueDates = [];

  let filteredWeather = data.list.filter(function (item) {
    let date = item.dt_txt.split(" ")[0];

    if (uniqueDates.includes(date)) {
      return false;
    } else {
      uniqueDates.push(date);
      return true;
    }
  });

  return filteredWeather;
};

Object.defineProperty(String.prototype, "capitalize", {
  value: function () {
    return this.charAt(0).toUpperCase() + this.slice(1);
  },
  enumerable: false,
});
